package com.winsomely.leecode;

/**
 * 寻找峰值
 * 
 * @author liujiawei
 *
 */
public class FindPeakElement {

	public int findPeakElement(int[] nums) {
		if (nums.length == 1) {
			return 0;
		}
		if (nums.length == 2) {
			return nums[0] > nums[1] ? 0 : 1;
		}
		for (int i = 1; i < nums.length - 1; i++) {
			if (nums[i - 1] < nums[i] && nums[i] > nums[i + 1]) {
				return i;
			}
		}
		return nums[0] > nums[nums.length - 1] ? 0 : nums.length - 1;
	}

	public static void main(String[] args) {
		FindPeakElement t = new FindPeakElement();
		int[] nums = {5,4,3,2 };
		System.out.println(t.findPeakElement(nums));
	}

}
